/*
 * 文件名：SyncManager.java	 
 * 时     间：上午9:22:14
 * 作     者：lyf      
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.schedule.log;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.CloseableHttpClient;

import com.cz073586.tools.http.HttpManagerUtil;
import com.local.manager.cfgManager.CloudConfigManager;
import com.local.util.HttpClientUtil;

/**
 * 类描述: 管理系统与云通信异常，等网络恢复时再把数据同步到云
 * 
 * @ClassName: SyncManager
 * @author lyf
 * @date 2015年11月26日 上午9:22:14
 */
public class SyncManager
{
	private static SyncManager instance;
	
	private SyncManager()
	{
		
	}
	
	/**
	 * 
	 * 方法描述：
	 * 
	 * @Title: instance
	 * @param @return
	 * @return SyncManager
	 * @user lyf 2015年11月26日
	 * @throws
	 */
	public static SyncManager instance()
	{
		if (null == instance)
		{
			instance = new SyncManager();
		}
		
		return instance;
	}
	
	/**
	 * 
	 * 方法描述：检查云服务器是否连通
	 * 
	 * @Title: checkCloudService
	 * @param @return
	 * @return boolean
	 * @user lyf 2015年11月26日
	 * @throws
	 */
	public boolean checkCloudService()
	{
		CloseableHttpClient httpClient = HttpManagerUtil.getInstance()
				.getHttpClient(null);
		try
		{
			String host = CloudConfigManager.instance().getHost();
			HttpGet get = new HttpGet(host);
			get.setConfig(HttpClientUtil.getTimeOutCfg(0));
			
			CloseableHttpResponse response = httpClient.execute(get);
			response.close();
			return true;
		} catch (ClientProtocolException e)
		{
			return false;
		} catch (HttpHostConnectException e)
		{
			return false;
		} catch (IOException e)
		{
			return false;
		} finally
		{
			try
			{
				httpClient.close();
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] agrs)
	{
		System.out.println(SyncManager.instance().checkCloudService());
	}
}
